﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class admin_ManageInventory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDataGrid(1);
        }
        else
        {

        }
    }
    #region Bind data to grid
    protected void BindDataGrid(int pageIndex)
    {
        try
        {
            grdInventory.DataSource = Invetory_session.Get_InvetoryAsTable("", "order by Inv_ID DESC");
            grdInventory.DataBind();
        }
        catch (Exception ex)
        {
            //throw ex;
        }

    }
    #endregion


    protected void grdInventory_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdInventory.PageIndex = e.NewPageIndex;
        BindDataGrid(grdInventory.PageIndex);
    }
    protected void grdInventory_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        string strProductID = e.CommandArgument.ToString().Trim();
        string strCommand = e.CommandName;
        switch (strCommand)
        {

            case "delete_Inventory":

                try
                {

                    Invetory invetory = Invetory_session.Get_Invetory_ByID(strProductID);
                    if (invetory == null) return;
                    WebMsgBox.Show(strProductID.ToString());
                    Invetory_session.Delete_Invetory(invetory);

                    WebMsgBox.Show("Đã xóa thành công");
                    BindDataGrid(1);
                }
                catch (Exception ex)
                {
                    //throw ex;
                }
                break;
        }
    }
}
